macroScript SkeletonExport category:"AirCrash"
(
	select $Bone*

	output_name = getSaveFileName caption:"XML Skeleton File" types:"Level (*.rig)|*.rig|"
	
	if output_name != undefined then 
	(
		output_file = createfile output_name

		format "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n" to:output_file
		format "<skeleton>\n" to:output_file

		id = 0
		
		for obj in selection do
		(
			angles = (obj.rotation) as eulerangles
			rx = degToRad angles.x
			ry = degToRad angles.y
			rz = degToRad angles.z
			
			format "\t<bone name=\"%\" length=\"%\" id=\"%\">\n" obj.name obj.length id to:output_file
			format "\t\t<pivot x=\"%\" y=\"%\" z=\"%\"></pivot>\n" obj.pivot.x obj.pivot.y obj.pivot.z to:output_file
			format "\t\t<transform tx=\"%\" ty=\"%\" tz=\"%\" rx=\"%\" ry=\"%\" rz=\"%\" sx=\"1\" sy=\"1\" sz=\"1\"></transform>\n" obj.pos.x obj.pos.y obj.pos.z rx ry rz to:output_file
			format "\t</bone>\n" to:output_file
			id += 1
		)
		format "</skeleton>\n" to:output_file
		
		close output_file
	)
	print "DONE"
)